package com.wyl.mine.shang

import androidx.recyclerview.widget.LinearLayoutManager
import com.wuhenzhizao.titlebar.widget.CommonTitleBar
import com.wyl.libbase.base.BindingActivity
import com.wyl.libbase.binding.recyclerview.RecyclerViewSpace
import com.wyl.mine.R
import com.wyl.mine.databinding.ShangActivityBinding
import io.ditclear.bindingadapter.SingleTypeAdapter
import org.koin.android.viewmodel.ext.android.viewModel

class ShangActivity : BindingActivity<ShangActivityBinding>() {
    private val viewModel: ShangViewModel by viewModel()

    override fun getLayoutId(): Int = R.layout.shang_activity

    private val mAdapter by lazy {
        SingleTypeAdapter(this, R.layout.shang_item, viewModel.dataSource)
    }

    private val mLayoutManager by lazy { LinearLayoutManager(this) }

    private val mDivider by lazy { RecyclerViewSpace() }

    override fun initView() {
        binding.vm = viewModel

        binding.titlebar.setListener { _, action, _ ->
            when (action) {
                CommonTitleBar.ACTION_LEFT_BUTTON -> onBackPressed()
                else -> {
                }
            }
        }

        binding.include.recyclerView.apply {
            layoutManager = mLayoutManager
            adapter = mAdapter
            addItemDecoration(mDivider)
        }
    }

    override fun loadData() {
        viewModel.refresh()

//        viewModel.loading.addOnPropertyChangedCallback(object : Observable.OnPropertyChangedCallback() {
//            override fun onPropertyChanged(sender: Observable?, propertyId: Int) {
//                if (viewModel.loading.get()) {
//                    showLoadingDialog()
//                } else if (!viewModel.loading.get()) {
//                    dissmissLoadingDialog()
//                }
//            }
//        })

    }
}
